<?php
/**
 * The form for updating an order.
 * @author Ian Dunn <scholar42@gmail.com>
 * @version 1.0
 * @since 2013-11-20
 */
require_once "login_info.php";
require_once "order.php";

loginInfo::update_login();

?>

<html>
	<head>
		<title>Opol - Update Orders</title>
	</head>
	<body>
		<link rel="stylesheet" type="text/css" href="opol.css">
		<?php require 'menu.php' ?>
		<br>

<?php
	if ($_POST) {
		$orderid = $_POST['orderid'];
		$action = $_POST['action'];
		if (!$orderid) {
			echo "Please specify an order id.<br>\n";
		} else if (!$action) {
			echo "Please specify an action.<br>\n";
		} else {

			$db = new database();

			$order = new order($orderid);
			$order->init ($db);

			switch ($action) {
				case "place_hold":
					$order->place_hold($db);
					break;
				case "remove_hold":
					$order->remove_hold($db);
					break;
				case "update_phases":
					$db->close ();
					header("location:update_phase.php?id=" . (string)$orderid);
					break;
			}

			$db->close ();
		}
	}
?>
		<a href="new_order.php">New Order</a><br>
		<form id="order" action="update_order.php" method="post">

		<table>
			<tr>
				<td><label for='orderid'>Order Id:</label></td>
				<td><input type="text" name="orderid"/></td>
			</tr>

			<tr>
				<td><label for='action'>Action:</label></td>
				<td><select name="action">
					<option value="place_hold">Place Hold</option>
					<option value="remove_hold">Remove Hold</option>
					<option value="update_phases">Update Phases</option>
				</select></td>
			</tr>
			<tr>
				<td><input type="submit" value="Go"></td>
			</tr>
		</table>
		</form>
	</body>
</html>
